package com.zzti.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzti.mapper.VisiterMapper;
import com.zzti.pojo.Goods;
import com.zzti.pojo.Visiter;
import com.zzti.service.VisiterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Service
public class VisiterServiceImpl implements VisiterService {

    public static Integer count;

    @Autowired
    private VisiterMapper visiterMapper;

    @Override
    public Visiter findOne(Integer id) {
        return visiterMapper.selectById(id);
    }

    @Override
    public Integer deleteByIds(Integer[] ids) {
        List<Integer> ls = Arrays.asList(ids);
        return visiterMapper.deleteBatchIds(ls);
    }


    @Override
    public Integer add(Visiter vs) {
        return visiterMapper.insert(vs);
    }

    /*  @Override
      public Integer update(Visiter vs) {
          return visiterMapper.updateById(vs);
      }
  */
    @Override
    public Integer update(Visiter vs) {
        if (vs.getAccount() != null) {
            Visiter vis = visiterMapper.selectOne(new QueryWrapper<Visiter>().eq("account", vs.getAccount()));
            System.out.println(vis.toString());
            vs.setId(vis.getId());
            System.out.println(vs.toString());
        }
        return visiterMapper.updateById(vs);
    }

    @Override
    public Visiter login(String account, String password) {
        QueryWrapper<Visiter> qw = new QueryWrapper<Visiter>();
        qw.eq("account", account);
        qw.eq("password", password);
        Visiter vs = (Visiter) visiterMapper.selectOne(qw);
        return vs;
    }

    @Override
    public List<Visiter> findOther(Map map) {

        List<Visiter> ls1 = visiterMapper.selectList(map);
        map.remove("page");
        map.remove("limit");
        List<Visiter> ls2 = visiterMapper.selectList(map);
        count = ls2.size();
        System.out.println(ls1.toString());
        return ls1;
    }

    @Override
    public List<Visiter> findAll(Map map) {
        return visiterMapper.selectList(map);
    }

    @Override
    public int updateById(Visiter entity) {
        return visiterMapper.updateById(entity);
    }


}
